// v100 by Michael Cammer 20140825 as a demonstration for Leonor Remedio // v101 and later modified for Willy Ramos to measure whether // The image must have one and only one overlay on it that is a closed ROI. // This macro requires a ROI Manager window populated with: // An unlimited number of ROIs. // The minimum length from each point is calculated to the line. // This shortest path is drawn for each. // Let's say there is a ROI Manager full of points but the big area to relate them to hasn't been // entered yet. macro "Make the last ROI the first" { requires("1.49k"); roiManager("select", roiManager("count")-1); roiManager("Rename", "0"); roiManager("Deselect"); roiManager("Sort"); } macro "Measure distance to line [q]" { requires("1.49k"); run("Remove Overlay"); // cleans up any previous overlays -- may be deleted or commented out getPixelSize(unit, pixelWidth, pixelHeight); run("Set Scale...", "distance=1 known=1 unit=pixel"); roiManager("select", 0); if (selectionType() > 4) exit ("First selection in RoiManager must be a closed shape."); // Check that the first selection is a closed object. run("Interpolate", "interval=2"); // half as fast and arguably more precise, change to 1 getSelectionCoordinates(x, y); Roi.setStrokeColor("#0080ff"); run("Add Selection..."); run("Set Measurements...", " centroid redirect=None decimal=0"); print("selection# \t distance"); for (selection=1; selection 0) min = min * (-1); print((selection+1) + " \t " + min + " \t pixels\t "+ (min*pixelWidth) + " \t " + unit); makeLine(xc, yc, lx, ly); if (inside > 0) color1 = "#ff00"; else color1 = "#00ff"; Roi.setStrokeColor(color1 + "ff"); run("Add Selection..."); } // for each selection run("Select None"); run("Set Scale...", "distance=1 known="+pixelWidth+" unit="+unit); // restore scale to image; assumes square pixels run("Clear Results"); selectWindow("Log"); }